package com.survey.Controller;

import com.survey.pojo.data.ConfigDO;
import com.survey.pojo.vo.ConfigVO;
import com.survey.service.ConfigService;
import com.survey.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * 网站配置
 */
@Controller
public class SystemConfigController {
    @Autowired
    private ConfigService configService;

    /**
     * 更新网站
     *
     * @param configVO
     * @return
     * @throws Exception
     */
    @RequestMapping("/admin/updateConfig")
    @ResponseBody
    public Result updateConfig(ConfigVO configVO,HttpSession session) throws Exception {
        Result result = configService.updateConfig(configVO);
        return result;
    }

    @RequestMapping("/admin/config")
    public String config(HttpSession session) throws Exception {
        List<ConfigDO> configDOS = configService.listConfig(new ConfigVO());
        if(configDOS!=null&&configDOS.size()!=0){
            ConfigDO configDO = configDOS.get(0);
            session.setAttribute("config",configDO);
        }
        return "/admin/SysConfig.jsp";
    }

}
